package com.wxh.multithread;

/**
 * @ClassName: TestYield
 * @Description: 测试让出线程
 * @Author wxh
 * @Date: 2021/12/30 14:10
 * @Version V1.0.0
 * @Since 1.8
 */
public class TestYield {
    public static void main(String[] args) {
        MyYield myYield = new MyYield();
        new Thread(myYield, "a").start();
        new Thread(myYield, "b").start();
    }
}

class MyYield implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "开始线程");
        // 礼让当前线程
        Thread.yield();
        System.out.println(Thread.currentThread().getName() + "停止线程");
    }
}